package lab03.test13;

import java.sql.*;

public class Test13 {
    public static void main(String[] args) {

        //3+1
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        String sql = "insert into" +
                " t_students(real_name, age, gender, department, stu_no)" +
                " values('lin',19,1,'信息与工程学院','1606101106')";

        try {

            //加载驱动程序
            Class.forName("com.mysql.cj.jdbc.Driver");

            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                    "root",
                    "123456");

            statement = connection.createStatement();

            //ResultSet:数据库的基本操作增删改查，只有查询时才需要

            //执行Sql语句
            statement.execute(sql);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {

            //关闭程序
            try {
                statement.close();
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
